$OpenBSD: patch-Makefile,v 1.7 2015/05/09 06:50:02 benoit Exp $

1. Do not force some compilation flags.
2. Set library version, respecting OpenBSD policy.
3. Avoid duplication of defines, linked to (2).
4. Do not use $(INSTALL_*) at the build stage.

--- Makefile.orig	Fri May  8 11:06:59 2015
+++ Makefile	Sat May  9 08:34:16 2015
@@ -30,7 +30,7 @@ ifneq (,$(findstring yes,$(CAPSTONE_DIET)))
 CFLAGS ?= -Os
 CFLAGS += -DCAPSTONE_DIET
 else
-CFLAGS ?= -O3
+CFLAGS ?= 
 endif
 
 ifneq (,$(findstring yes,$(CAPSTONE_X86_ATT_DISABLE)))
@@ -82,8 +82,11 @@ INSTALL_DATA ?= $(INSTALL_BIN) -m0644
 INSTALL_LIB ?= $(INSTALL_BIN) -m0755
 
 LIBNAME = capstone
+LIBVER ?= 0.0.0
+ifdef LIB$(LIBNAME)_VERSION
+LIBVER = $(LIB$(LIBNAME)_VERSION)
+endif
 
-
 DEP_ARM =
 DEP_ARM += arch/ARM/ARMGenAsmWriter.inc
 DEP_ARM += arch/ARM/ARMGenDisassemblerTables.inc
@@ -282,7 +285,7 @@ else
 EXT = so
 VERSION_EXT = $(EXT).$(API_MAJOR)
 AR_EXT = a
-$(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME).$(VERSION_EXT)
+$(LIBNAME)_LDFLAGS += -Wl,-soname,lib$(LIBNAME)
 endif
 endif
 endif
@@ -293,7 +296,7 @@ LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT)
 else ifeq ($(IS_CYGWIN),1)
 LIBRARY = $(BLDIR)/$(LIBNAME).$(EXT)
 else	# *nix
-LIBRARY = $(BLDIR)/lib$(LIBNAME).$(EXT)
+LIBRARY = $(BLDIR)/lib$(LIBNAME).$(EXT).$(LIBVER)
 CFLAGS += -fvisibility=hidden
 endif
 endif
@@ -320,7 +323,7 @@ else
 	cd tests && $(MAKE) BUILDDIR=$(BLDIR)
 endif
 ifeq ($(CAPSTONE_SHARED),yes)
-	$(INSTALL_DATA) $(LIBRARY) $(BLDIR)/tests/
+	cp $(LIBRARY) $(BLDIR)/tests/
 endif
 endif
 
@@ -367,13 +370,9 @@ endif
 install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY)
 	mkdir -p $(LIBDIR)
 ifeq ($(CAPSTONE_SHARED),yes)
-	$(INSTALL_LIB) $(LIBRARY) $(LIBDIR)
-ifneq ($(VERSION_EXT),)
-	cd $(LIBDIR) && \
-	mv lib$(LIBNAME).$(EXT) lib$(LIBNAME).$(VERSION_EXT) && \
-	ln -s lib$(LIBNAME).$(VERSION_EXT) lib$(LIBNAME).$(EXT)
+	$(INSTALL_LIBRARY) $(LIBRARY) $(LIBDIR)
+	$(INSTALL_DATA) $(ARCHIVE) $(LIBDIR)
 endif
-endif
 ifeq ($(CAPSTONE_STATIC),yes)
 	$(INSTALL_DATA) $(ARCHIVE) $(LIBDIR)
 endif
@@ -383,13 +382,12 @@ endif
 	$(INSTALL_DATA) $(PKGCFGF) $(PKGCFGDIR)/
 
 uninstall:
-	rm -rf $(INCDIR)/$(LIBNAME)
-	rm -f $(LIBDIR)/lib$(LIBNAME).*
-	rm -f $(PKGCFGDIR)/$(LIBNAME).pc
+	rm -f $(LIBDIR)/$(LIBRARY)
+	rm -f $(LIBDIR)/$(ARCHIVE)
+	rm -f $(LIBDIR)/pkgconfig/$(PKGCFGF)
 
 clean:
-	rm -f $(LIBOBJ)
-	rm -f $(BLDIR)/lib$(LIBNAME).* $(BLDIR)/$(LIBNAME).*
+	rm -f $(LIBOBJ) $(ARCHIVE) $(LIBRARY)
 	rm -f $(PKGCFGF)
 
 ifeq (,$(findstring yes,$(CAPSTONE_BUILD_CORE_ONLY)))
